import datetime
import time
import random
import os

# 删除data.txt文件，并创建新的data.txt文件
def delet_new_data():
    os.remove("D:/hello Python/邓老师任务/test5/data.txt")
    data_txt = open("D:/hello Python/邓老师任务/test5/data.txt","a")
    data_txt.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+"\n")
    line_num = 1
    lines_list = []
    while line_num < 11 :
        random_num = random.random()
        data_txt.write("%s\t%s\tNULL\n"%(line_num,random_num))
        line_num += 1
    print("生成数据，时间戳：%s"%str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))

def main():
    while True :
        delet_new_data()
        # 每隔0.5s执行一次程序
        time.sleep(0.5)




if __name__ == '__main__':
    main()
           
